package com.bms.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;

import com.bms.Logic;
import com.bms.abstracts.RESTController;
import com.bms.domain.Event;
import com.bms.domain.Groups;
import com.bms.domain.User;

public class TaskController extends RESTController {
	
	private Logic logic;

	public void setLogic(Logic logic) {
		this.logic = logic;
	}

	@Override
	protected ModelAndView doGet(HttpServletRequest request,
			HttpServletResponse response) {
		// List<Event> list = logic.getGongZuoJiHuaList();
		List<Groups> groups = logic.getGroupList();
		request.setAttribute("groups", groups);
		return new ModelAndView("task");
	}

	@Override
	protected ModelAndView doPost(HttpServletRequest request,
			HttpServletResponse response) {
		String title = request.getParameter("title");
		String createtime = logic.getCurrentDate();
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String status = request.getParameter("status");
		String summary = request.getParameter("summary");
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String eventId = request.getParameter("eventId");
		Event event = new Event();
		event.setTitle(title);
		event.setStartTime(startTime);
		event.setEndTime(endTime);
		event.setStatus(status);
		event.setCreatetime(createtime);
		event.setSummary(summary);
		event.setUser(user);
		event.setEventId(Integer.parseInt(eventId));
		logic.addEvent(event);
		return doGet(request,response);
	}

}
